﻿using System.Windows;
using wi=System.Windows.Interactivity;
using Thinktecture.UIAnnotations.Behaviors;

namespace Demo
{
    public partial class BehaviorsDemoWindow : Window
    {
        public BehaviorsDemoWindow()
        {
            InitializeComponent();
            this.Loaded += this.OnLoaded;
        }

        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            //this.AssignBehaviors();
        }
        
        private void AssignBehaviors()
        {
            // assign Behaviors via code
            var focusBehavior = new FocusBehavior();
            var behaviors = wi.Interaction.GetBehaviors(this.imageTextBox);
            behaviors.Add(focusBehavior);
            
            // apply TriggerAction
            var numericInputBehavior = new NumericInputBehavior();
            var numericTrigger = new wi.EventTrigger();
            numericTrigger.EventName = "KeyDown";
            numericTrigger.Actions.Add(numericInputBehavior);
            var triggers = wi.Interaction.GetTriggers(this.firstNameTextBox);
            triggers.Add(numericTrigger);

            // apply TargetedTriggerAction
            var openFileBehavior = new OpenFileBehavior();
            openFileBehavior.DialogTitle = "Open File...";
            openFileBehavior.Filter = "All Files|*.*";
            openFileBehavior.TargetObject = this.imageTextBox;
            var openFileTrigger = new wi.EventTrigger();
            openFileTrigger.EventName = "Click";
            openFileTrigger.Actions.Add(openFileBehavior);
            var buttonTriggers = wi.Interaction.GetTriggers(this.searchButton);
            buttonTriggers.Add(openFileTrigger);
        }
    }
}
